home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Express Pd: GALORE
/
Express Pd Galore - The Amiga PD & Shareware CD (1994)(Express Pd)[!][Amiga-CD32-CDTV].iso
/
productivity
/
term
/
termsendtext.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-16
|
8KB
|
529 lines
/*
** termSendText.c
**
** Text sending support routines
**
** Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
** All Rights Reserved
*/
#include "termARexxGlobal.h"
/* Local variables. */
STATIC LONG WaitCount,PromptCount;
/* MatchPrompt():
*
* Search incoming data stream for a match.
*/
STATIC BYTE __regargs
MatchPrompt(register STRPTR Data,register LONG Size,register STRPTR Prompt,register LONG PromptLen)
{
register UBYTE c,Mask;
if(Config -> SerialConfig -> StripBit8)
Mask = 0x7F;
else
Mask = 0xFF;
do
{
if(c = ((*Data++) & Mask))
{
register BYTE MatchMade;
do
{
MatchMade = FALSE;
if(PromptCount == WaitCount)
{
if(c == Prompt[WaitCount] & Mask)
{
MatchMade = TRUE;
if(PromptLen == ++PromptCount)
return(TRUE);
}
}
if(MatchMade)
WaitCount++;
else
{
if(WaitCount)
{
WaitCount = 0;
PromptCount = 0;
}
else
break;
}
}
while(!WaitCount);
}
}
while(--Size);
return(FALSE);
}
/* WaitForPrompt(STRPTR Prompt,LONG PromptLen):
*
* Scan the incoming data flow for a certain string.
*/
STATIC BYTE __regargs
WaitForPrompt(STRPTR Prompt,LONG PromptLen)
{
ULONG Signals;
WaitCount = PromptCount = 0;
if(DataHold)
{
DataHold = NULL;
RestartSerial();
}
if(CheckIO(ReadRequest))
Signals = SIG_SERIAL;
else
Signals = NULL;
StartTime(Config -> ClipConfig -> SendTimeout / 100,(Config -> ClipConfig -> SendTimeout % 100) * 10000);
for(;;)
{
if(Signals & SIG_SERIAL)
{
if(!WaitIO(ReadRequest))
{
LONG Length;
BytesIn++;
ConProcess(ReadBuffer,1);
Status = STATUS_READY;
if(MatchPrompt(ReadBuffer,1,Prompt,PromptLen))
{
if(!CheckIO(TimeRequest))
AbortIO(TimeRequest);
WaitIO(TimeRequest);
RestartSerial();
return(TRUE);
}
do
{
/* Check how many bytes are still in
* the serial buffer.
*/
WriteRequest -> IOSer . io_Command = SDCMD_QUERY;
DoIO(WriteRequest);
if(Length = WriteRequest -> IOSer . io_Actual)
{
if(Length > Config -> SerialConfig -> SerialBufferSize)
Length = Config -> SerialConfig -> SerialBufferSize;
ReadRequest -> IOSer . io_Command = CMD_READ;
ReadRequest -> IOSer . io_Data = ReadBuffer;
ReadRequest -> IOSer . io_Length = Length;
if(!DoIO(ReadRequest))
{
BytesIn += Length;
ConProcess(ReadBuffer,Length);
Status = STATUS_READY;
if(MatchPrompt(ReadBuffer,Length,Prompt,PromptLen))
{
if(!CheckIO(TimeRequest))
AbortIO(TimeRequest);
WaitIO(TimeRequest);
RestartSerial();
return(TRUE);
}
}
}
}
while(Length);
}
RestartSerial();
}
if(Signals & SIG_TIMER)
{
WaitIO(TimeRequest);
return(FALSE);
}
Signals = Wait(SIG_SERIAL | SIG_TIMER);
}
}
/* SendLinePrompt(STRPTR Line,LONG Len):
*
* Send text line, wait for prompt.
*/
BYTE __regargs
SendLinePrompt(STRPTR Line,LONG Len)
{
LONG i;
if(Len == -1)
Len = strlen(Line);
while(Len)
{
i = 0;
while(i < Len && Line[i] != '\r')
i++;
if(Line[i] == '\r')
{
i++;
SerWrite(Line,i);
if(!WaitForPrompt(SendPrompt,SendPromptLen))
return(FALSE);
}
else
{
if(i)
SerWrite(Line,i);
}
Len -= i;
Line += i;
}
return(TRUE);
}
/* SendLineSimple(STRPTR Line,LONG Len):
*
* Send a text line, no fancy features.
*/
BYTE __regargs
SendLineSimple(STRPTR Line,LONG Len)
{
if(Len == -1)
Len = strlen(Line);
SerWrite(Line,Len);
return(TRUE);
}
/* SendLineDelay(STRPTR Line,LONG Len):
*
* Send a text line, include a delay where necessary.
*/
BYTE __regargs
SendLineDelay(STRPTR Line,LONG Len)
{
if(Len == -1)
Len = strlen(Line);
while(Len--)
{
SerWrite(Line,1);
if(*Line == '\r')
{
if(Config -> ClipConfig -> LineDelay)
WaitTime(Config -> ClipConfig -> LineDelay / 100,(Config -> ClipConfig -> LineDelay % 100) * 10000);
}
else
{
if(Config -> ClipConfig -> CharDelay)
WaitTime(Config -> ClipConfig -> CharDelay / 100,(Config -> ClipConfig -> CharDelay % 100) * 10000);
}
Line++;
}
return(TRUE);
}
/* SendLineEcho(STRPTR Line,LONG Len):
*
* Send a text line, wait for single characters to be echoed.
*/
BYTE __regargs
SendLineEcho(STRPTR Line,LONG Len)
{
ULONG Signals;
if(DataHold)
{
DataHold = NULL;
RestartSerial();
}
if(Len == -1)
Len = strlen(Line);
while(Len--)
{
SerWrite(Line,1);
StartTime(Config -> ClipConfig -> SendTimeout / 100,(Config -> ClipConfig -> SendTimeout % 100) * 10000);
FOREVER
{
Signals = Wait(SIG_TIMER | SIG_SERIAL);
if(Signals & SIG_SERIAL)
{
if(!WaitIO(ReadRequest))
{
if(*(UBYTE *)ReadBuffer == *Line)
{
if(!CheckIO(TimeRequest))
AbortIO(TimeRequest);
WaitIO(TimeRequest);
RestartSerial();
break;
}
RestartSerial();
}
else
{
if(!CheckIO(TimeRequest))
AbortIO(TimeRequest);
WaitIO(TimeRequest);
RestartSerial();
return(FALSE);
}
}
if(Signals & SIG_TIMER)
{
WaitIO(TimeRequest);
return(FALSE);
}
}
Line++;
}
return(TRUE);
}
/* SendLineAnyEcho(STRPTR Line,LONG Len):
*
* Send a text line, wait for characters to be echoed.
*/
BYTE __regargs
SendLineAnyEcho(STRPTR Line,LONG Len)
{
ULONG Signals;
if(DataHold)
{
DataHold = NULL;
RestartSerial();
}
if(Len == -1)
Len = strlen(Line);
while(Len--)
{
SerWrite(Line,1);
StartTime(Config -> ClipConfig -> SendTimeout / 100,(Config -> ClipConfig -> SendTimeout % 100) * 10000);
FOREVER
{
Signals = Wait(SIG_TIMER | SIG_SERIAL);
if(Signals & SIG_SERIAL)
{
if(!WaitIO(ReadRequest))
{
if(!CheckIO(TimeRequest))
AbortIO(TimeRequest);
WaitIO(TimeRequest);
RestartSerial();
break;
}
else
{
if(!CheckIO(TimeRequest))
AbortIO(TimeRequest);
WaitIO(TimeRequest);
RestartSerial();
return(FALSE);
}
}
if(Signals & SIG_TIMER)
{
WaitIO(TimeRequest);
return(FALSE);
}
}
Line++;
}
return(TRUE);
}
/* SendLineKeyDelay(STRPTR Line,LONG Len):
*
* Send a text line, include keyboard delay pauses between characters.
*/
BYTE __regargs
SendLineKeyDelay(STRPTR Line,LONG Len)
{
struct Preferences Prefs;
if(Len == -1)
Len = strlen(Line);
/* Get current key repeat delay. */
GetPrefs(&Prefs,offsetof(struct Preferences,KeyRptDelay));
/* Any delay specified at all? */
if(Prefs . KeyRptSpeed . tv_secs || Prefs . KeyRptSpeed . tv_micro)
{
while(Len--)
{
SerWrite(Line++,1);
if(Len)
{
TimeRequest -> tr_node . io_Command = TR_ADDREQUEST;
TimeRequest -> tr_time = Prefs . KeyRptSpeed;
DoIO(TimeRequest);
}
}
}
else
SerWrite(Line,Len);
return(TRUE);
}
/* SendSetup():
*
* Choose the right routine for the text line output job.
*/
VOID
SendSetup()
{
/* Prepare the prompt string. */
if(Config -> ClipConfig -> LinePrompt[0])
SendPromptLen = TranslateString(Config -> ClipConfig -> LinePrompt,SendPrompt);
else
{
SendPrompt[0] = 0;
SendPromptLen = 0;
}
/* Pick the line send routine. */
switch(Config -> ClipConfig -> PacingMode)
{
case PACE_DIRECT:
SendLine = SendLineSimple;
break;
case PACE_ECHO:
if(Config -> ClipConfig -> SendTimeout)
SendLine = SendLineEcho;
else
SendLine = SendLineSimple;
break;
case PACE_ANYECHO:
if(Config -> ClipConfig -> SendTimeout)
SendLine = SendLineAnyEcho;
else
SendLine = SendLineSimple;
break;
case PACE_PROMPT:
if(Config -> ClipConfig -> SendTimeout)
SendLine = SendLinePrompt;
else
SendLine = SendLineSimple;
break;
case PACE_DELAY:
if(Config -> ClipConfig -> LineDelay || Config -> ClipConfig -> CharDelay)
SendLine = SendLineDelay;
else
SendLine = SendLineSimple;
break;
case PACE_KEYBOARD:
SendLine = SendLineKeyDelay;
break;
}
}